package com.fjwt.gz.mch.ctrl.lite.banner;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fjwt.gz.core.exception.BizException;
import com.fjwt.gz.core.model.ApiRes;
import com.fjwt.gz.db.dto.LiteBannerDTO;
import com.fjwt.gz.db.entity.LiteBannerEntity;
import com.fjwt.gz.db.vo.LiteBannerVO;
import com.fjwt.gz.mch.ctrl.CommonCtrl;
import com.fjwt.gz.service.impl.LiteBannerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 轮播图接口类
 */
@Slf4j
@RestController
@RequestMapping("/api/liteBanner")
public class LiteBannerController extends CommonCtrl {
    @Autowired
    private LiteBannerService liteBannerService;

    /**
     * 获取轮播图列表
     */
    @PostMapping(value = "/list")
    public ApiRes getLiteBanner() {
        LiteBannerDTO dto = getObject(LiteBannerDTO.class);
        dto.setAppId(request.getHeader("appId"));
        log.info("C端轮播图列表参数，请求地址：/api/liteBanner/list，请求参数：{}", JSONUtil.toJsonStr(dto));
        String locationAgentNo =request.getHeader("locationAgentNo");
        dto.setAgentNo(locationAgentNo);
        IPage<LiteBannerVO> page = liteBannerService.selectLiteBannerList(getIPage(), dto);
        log.info("C端轮播图列表参数，请求地址：/api/liteBanner/list，返回结果：{}", JSONUtil.toJsonStr(page));
        return ApiRes.page(page);
    }

    /**
     * 轮播图详情
     */
    @PostMapping("/detail")
    public ApiRes getBannerDetail() {
        Long bannerId = getValLong("bannerId");
        log.info("C端轮播图详情参数，请求地址：/api/liteBanner/detail，请求参数：{}", JSONUtil.toJsonStr(bannerId));
        LiteBannerVO vo = liteBannerService.selectDetailById(bannerId);
        log.info("C端轮播图详情参数，请求地址：/api/liteBanner/detail，返回结果：{}", JSONUtil.toJsonStr(vo));
        return ApiRes.ok(vo);
    }
}
